<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/manager/base.jsp"%>
<!-- baidu js -->
<script type="text/javascript"
	src="http://api.map.baidu.com/getscript?v=1.4&ak=&services=&t=20180102095227"></script>
<!-- google js -->
<script
	src="http://webapi.amap.com/maps?v=1.4.7&key=0861c3ca222363fe2bd8679d2050e445"></script>
<p id="demo">点击这个按钮，获得您的坐标：</p>
<button onclick="getLocation()">试一下</button>
<div id="iMap"></div>

<div id="container"></div>
<script>
	var x = document.getElementById("demo");
	function getLocation() {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(showPosition);
		} else {
			x.innerHTML = "Geolocation is not supported by this browser.";
		}
	}
	function showPosition(position) {	
		getAddress(position.coords.longitude, position.coords.latitude);
		gogleGetAddress(position);
		x.innerHTML = "Latitude: " + position.coords.latitude
				+ "<br />Longitude: " + position.coords.longitude;
	}
	
	function gogleGetAddress(position){
		AMap.plugin('AMap.Geocoder', function() {
			var geocoder = new AMap.Geocoder({})
			var lnglat = [position.coords.longitude,position.coords.latitude]
			geocoder.getAddress(lnglat, function(status, result) {
				if (status === 'complete' && result.info === 'OK') {
					// result为对应的地理位置详细信息
					var address = result.regeocode.formattedAddress; //返回地址描述
					$("#container").html(address);
				}
			})
		})
	}

	function getAddress(longitude, latitude) {
		//通过baiduMap API获取街道名称
		var map = new BMap.Map("iMap");
		var point = new BMap.Point(longitude, latitude);
		var gc = new BMap.Geocoder();
		gc.getLocation(point, function(rs) {
			$("#iMap").html(rs.address);
		});
	}
</script>
<script type="text/javascript">
	
</script>
</body>